<template>
  <el-dialog v-model="show" title="导入表格" width="500">
    <div style="padding-bottom: 30px; text-align: center">
      <el-link @click="handleTemplate">下载模板</el-link>
    </div>
    <el-form :model="form" class="demo-form-inline">
      <el-form-item label="文件">
        <yu-upload  @update:modelValue="uploadOk" url="/admin/supplier/importExcel" />
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script setup>
import { download } from "@/utils/http.js";
const emit = defineEmits(['refreshDataList']);
const show = ref(false);
const form = ref({});
const init = () => {
  show.value = true;
};

const handleTemplate = () => {
  let fileName = "供应商导入模板_" + new Date().getTime() + ".xlsx";
  download("/admin/supplier/exportExcel", undefined, fileName);
};
const uploadOk = (res) => {
  console.log(res);
  if (res.success) {
    ElMessage({
      message: "导入成功！",
      type: "success",
    });
    emit('refreshDataList')
  } else {
    ElMessage({
      message: "导入失败！" + res.msg,
      type: "Error",
    });
  }
  show.value = false;
};

defineExpose({ init });
</script>